<template>
    <div class="home-recommond">
        <div class="tabs">
            <h3>推荐歌单</h3>
            <a href="#">更多></a>
        </div>
        <div class="wrapper" ref="wrapper">
            <ul class="content" ref="content">
            <li v-for="(item,index) in listData" :key="index" @click="selectItem(item)">
                    <div class="cover">
                        <van-image :src="item.picUrl" radius="1rem" />
                        <span>▷{{item.playCount| numFilter(1)}}万</span>
                    </div>
                    <span>{{item.name}}</span>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import { betterScrollHorizontal } from "@/common/betterScroll.js";
export default {
    data() {
        return {
            listData: []
        }
    },
    /* 一个vue实例被生成后会调用created函数
    一般可以在此函数中调用ajax获取页面 */
    created() {
        this.getSongListData()
    },
    methods: {
        //获取推荐歌单数据
        getSongListData() {
            this.$request('get', '/personalized').then(res => {
                console.log(res)
                if (res.code == 200) {
                    this.listData = res.result;
                }
                console.log(this.listData)
                // 异步数据的一些处理
                betterScrollHorizontal(
                    this,
                    this.$refs.wrapper,
                    this.$refs.content,
                    this.listData.length,
                    8
                );
            });
        },
        selectItem(item) {
            const id = item.id;
            // console.log(id)
            this.$router.push(`/songlist/${id}`);
        }
    },
    filters: {
        numFilter(value, num) {
            return parseFloat(value / 10000).toFixed(num)
        }
    }

};
</script>

<style scoped>
.tabs {
    margin: 0 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tabs>a {
    color: rgba(61, 59, 59, 0.5);
    font-size: 5px;
}

.cover>span {
    position: absolute;
    right: 0.2rem;
    bottom: 0.3rem;
    /* background-color:#aaa4a469; */
    color: white;
    font-size: 1px;
    /* border-radius: 1rem; */
    width: 5rem;
    display: inline-block;
}

.cover {
    position: relative;
}

.wrapper {
    width: 100%;
    overflow: hidden;
}

ul.content li {
    /* li默认是块级元素，修改为行内元素，当时要具备块级元素的特证 */
    width: 8rem;
    display: inline-block;
    vertical-align: top;
}

ul.content li * {
    margin: 0.1rem;
}

ul.content li>span {
    font-size: 0.4rem;
    color: #544e46,
    
}
</style>